// Buffer类
// 在nodejs中，Buffer是用于处理二进制数据的类

// 使用Buffer来读取和写入数据：

// 创建一个Buffer实例，容量为10个字符
let buffer1 = Buffer.alloc(10);

// 读写数据
buffer1.write('hello','utf-8');
console.log( buffer1 );// <Buffer 68 65 6c 6c 6f 00 00 00 00 00>
console.log( buffer1.toString('utf-8') );// 'hello'

// 将字符串转成Buffer实例
let str = 'hello';
let buffer2 = Buffer.from(str,'utf-8');
console.log( buffer2 );// <Buffer 68 65 6c 6c 6f>

let buffer3 = Buffer.from([104,101,108,108,111]);
console.log( buffer3 );// <Buffer 68 65 6c 6c 6f>
console.log( buffer3.toString('utf-8') );// 'hello'
